package com.xmy.cultivate.util;

import com.xmy.cultivate.entity.Quarter;

import java.util.Date;
import java.util.Map;
import java.util.Random;

public class CommonUtil {

    /**
     * 判断两个值的季度相差多少
     */
    public static Integer diffQuarter(Map<String,Integer> map){
        Integer oldYear = map.get("oldYear");
        Integer oldNum = map.get("oldNum");
        Integer newYear = map.get("newYear");
        Integer newNum = map.get("newNum");

        Integer diffYear = newYear - oldYear;
        Integer diffNum = (newYear - oldYear) * 4 + newNum - oldNum;

        return diffNum;
    }

    public static int getNotSimple(int[] param, int len) {
        Random rand = new Random();
        for (int i = param.length; i > 1; i--) {
            int index = rand.nextInt(i);
            int tmp = param[index];
            param[index] = param[i - 1];
            param[i - 1] = tmp;
        }
        int result = 0;
        for (int i = 0; i < len; i++) {
            result = result * 10 + param[i];
        }
        return result;
    }

    /**
     * 获取年级段，如少儿,小学，初中,高中（0，1，2年级属于少儿）
     * @return
     */
    public static Integer getGradeSection(Integer yearClassId){
        Integer gradeSection = 100;//默认100
        if (yearClassId <=2){
            gradeSection = 0;
        }else if (yearClassId >2 && yearClassId<=6){
            gradeSection = 1;
        }else if (yearClassId>6 && yearClassId<=9){
            gradeSection = 2;
        }else if (yearClassId>9 && yearClassId<=12){
            gradeSection = 3;
        }
        return gradeSection;
    }

    /**
     * 获取下一学期
     * @param yearPart
     * @param quarterNum
     * @return
     */
    public static Quarter getNextQuarter(Integer yearPart, Integer quarterNum){
        Integer nextYearPart = yearPart;
        Integer nextQuarterNum = 0;
        if (quarterNum.equals(4)){
            nextQuarterNum =1;
            nextYearPart = nextYearPart + 1;
        }else {
            nextQuarterNum = quarterNum + 1;
        }
        Quarter quarter = new Quarter();
        quarter.setYearPart(nextYearPart);
        quarter.setNum(nextQuarterNum);
        return quarter;
    }

    /**
     * 获取科目
     * @param id
     * @return
     */
    public static String getLessonTypeName(Integer id){
        String[] dataArr = new String[]{"","精品课","智能课","刷题班"};
        String name = "";
        if(id>=0 && id<dataArr.length){
            name =dataArr[id];
        }
        return name;
    }
}
